package HierarchyPackage.SimpleHierarchy;

import HierarchyPackage.*;

/**
 * Classification class belonging to a SimpleHierarchy.
 * This class can not be instantiated - only returned from a SimpleHierarchy
 * (i.e. only a SimpleHierarchy can instantiate it).
 *
 * @author Martin Haulrich
 */
public final class SimpleHClass implements HClass{
    
    /**
     * Identifier to class in SimpleHierarchy
     */
    
    public final Integer classID;
    /**
     * The SimplerHierarchy this class belongs to
     */
    final SimpleHierarchy hier;
    
    
    /**
     * Constructor
     * @param hier The SimpleHierarchy that this classification-class will belong to
     * @param classID The ID for the class in <code>hier</code> corresponding to this class.
     */
    public SimpleHClass(SimpleHierarchy hier, Integer classID) {
        this.classID = classID;
        this.hier = hier;
    }
    
    
    /**
     * Returns ID for this class.
     * @return Returns ID for class in <code>hier</code> corresponding to this class.
     */
    public Integer getID() {
        return classID;
    }
    
    
    @Override
    public String getName() {
        return hier.getName(this);
    }
    
    
    @Override
    public Hierarchy belongsTo() {
        return hier;
    }
    
    @Override
    public int hashCode() {
      return classID.hashCode();  
    }
        
    @Override
    public boolean equals(Object o) {
        if (o instanceof SimpleHClass) {
            return ((SimpleHClass) o).getID().equals(classID);
        }
        return false;
    } 
}
